/*
 * Parallel.c
 *
 *  Created on: Nov 5, 2011
 *      Author: Philip Rodriguez, Oliver Wing
 *
 *  Mechanism to kick off the A/D conversion by monitoring
 *  a low-to-high signal from Freescale
 */

#include <stdio.h>
#include <stdlib.h>       /* for EXIT_* */
#include <stdint.h>       /* for uintptr_t */
#include <hw/inout.h>     /* for in*() and out*() functions */
#include <sys/neutrino.h> /* for ThreadCtl() */
#include <sys/mman.h>     /* for mmap_device_io() */
#include "Parallel.h"
#include "types.h"

// Initialize the settings to monitor interrupts on
// the parallel port
void initParallelPort(void)
{
	uintptr_t ctrl_handle;
	struct sigevent event;

	// Get a handle to the parallel port's control register
	ctrl_handle = mmap_device_io( PORT_LENGTH, CTRL_ADDRESS );
	// Initialize and enable interrupts on the parallel port
	out8( ctrl_handle, INIT_BIT | INTR_BIT );

	// Tell the kernel to attach an interrupt signal event to this thread
	event.sigev_notify = SIGEV_INTR;
	interruptId = InterruptAttachEvent( PARALLEL_IRQ, &event, 0 );
	if ( interruptId == -1 )
	{
		printf( "Couldn't attach event to IRQ %d\n", PARALLEL_IRQ );
	}
}
